<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">     
/******************************************************************
*Server    :  <xsl:value-of select="//Server"/>
*Database  :  <xsl:value-of select="//Database"/>
*name  :  dbo.UP_<xsl:value-of select="//Meta/Name"/>_Paging
*function  :  
*author    :  <xsl:value-of select="//Author"/>
*CreateDate   :  <xsl:value-of select="//CreateDate"/>
*Description  :  
*Reference Version : V1.0
=====================================================================
*change history
----------------------------------------------------------
*V1.0
*Date  : <xsl:value-of select="//CreateDate"/>
*Modify by : <xsl:value-of select="//Author"/>
*Description  : 
********************************************************************/
CREATE PROCEDURE dbo.UP_<xsl:value-of select="//Meta/Name"/>_Paging
  @pageSize int,
  @pageNo int
  AS

  declare @rowStart int
  set @rowStart = (@pageNo-1)*@pageSize+1;

  WITH t AS
  (
  SELECT ROW_NUMBER() OVER(ORDER BY <xsl:for-each select="//Meta/Columns/Column[IsPrimaryKey='true']">
	  <xsl:text>&#9;</xsl:text><xsl:value-of select="Name"/><xsl:if test="position()!=last()"> , </xsl:if>
  </xsl:for-each> ASC) AS rowNo, <xsl:for-each select="//Meta/Columns/Column"><xsl:value-of select="Name"/><xsl:if test="position()!=last()">,&#10;</xsl:if>
  </xsl:for-each>
  FROM <xsl:value-of select="//Meta/Name"/>
  )
  SELECT * from t
  WHERE rowNo
  BETWEEN @rowStart AND @rowStart + @pageSize-1

  </xsl:template>

</xsl:stylesheet>
